package com.xsomnus.open.imv2.serialize.impl;

import com.alibaba.fastjson.JSON;
import com.xsomnus.open.imv2.serialize.Serializer;
import com.xsomnus.open.imv2.serialize.SerializerAlgorithm;

/**
 * @author @xsomnus666_xiawenye★
 * @since 2019/4/24 0024 16:52
 * 当你发现自己的才华撑不起野心时，就请安静下来学习吧
 * 基于fastJson的序列化实现类(序列化的性能影响蛮大)
 */
public class FastJSONSerializer implements Serializer {

    @Override
    public byte getSerializerAlgorithm() {
        return SerializerAlgorithm.JSON;
    }

    @Override
    public byte[] serialize(Object object) {
        return JSON.toJSONBytes(object);
    }

    @Override
    public <T> T deserializer(Class<T> clazz, byte[] bytes) {
        return JSON.parseObject(bytes, clazz);
    }
}
